import $ from 'jquery'
import { GET_LIST } from '../config'
import crateItem from './CrateItem'

export default class List {
  constructor(app){
    console.log(app,'app')
    this.app = app;
    this.$el = $('div')

  }

  LoadData() {
    return fetch(GET_LIST).then(response => {
      return response.json()
    })
  }

  initItemList(data) {
    data.forEach((item) => {
      let newItem = crateItem(this, item);
      newItem.init()
    })
  }

  render() {
    this.app.$el.append(this.$el)
  }

  init() {
    this.LoadData().then((response) => {
      this.initItemList(response)
      this.render()
    })
  }
}